home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kacl.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-01-19  |  7.7 KB  |  208 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2005 Till Adam <adam@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __kacl_h__
  21. #define __kacl_h__
  22.  
  23. #include <sys/types.h>
  24. #include <kio/global.h>
  25.  
  26. typedef QPair<QString, unsigned short> ACLUserPermissions;
  27. typedef QValueList<ACLUserPermissions> ACLUserPermissionsList;
  28. typedef QValueListIterator<ACLUserPermissions> ACLUserPermissionsIterator;
  29. typedef QValueListConstIterator<ACLUserPermissions> ACLUserPermissionsConstIterator;
  30.  
  31. typedef QPair<QString, unsigned short> ACLGroupPermissions;
  32. typedef QValueList<ACLGroupPermissions> ACLGroupPermissionsList;
  33. typedef QValueListIterator<ACLGroupPermissions> ACLGroupPermissionsIterator;
  34. typedef QValueListConstIterator<ACLGroupPermissions> ACLGroupPermissionsConstIterator;
  35.  
  36. /**
  37.  * The KCAL class encapsulates a POSIX Access Control List. It follows the 
  38.  * little standard that couldn't, 1003.1e/1003.2c, which died in draft status.
  39.  * @short a POSIX ACL encapsulation
  40.  * @author Till Adam <adam@kde.org>
  41.  */
  42. class KIO_EXPORT KACL
  43. {
  44. public:
  45.   /**
  46.    * Creates a new KACL from @p aclString. If the string is a valid acl
  47.    * string, isValid() will afterwards return true.
  48.    */
  49.   KACL( const QString & aclString );
  50.  
  51.   /** Copy ctor */
  52.   KACL( const KACL& rhs );
  53.  
  54.   /** 
  55.    * Creates a new KACL from the basic permissions passed in @p basicPermissions.
  56.    * isValid() will return true, afterwards.
  57.    */
  58.   KACL( mode_t basicPermissions );
  59.  
  60.   /**
  61.    * Creates an empty KACL. Until a valid acl string is set via setACL,
  62.    * isValid() will return false.
  63.    */
  64.   KACL();
  65.  
  66.   virtual ~KACL();
  67.  
  68.   KACL& operator=( const KACL& rhs ) { 
  69.     if ( this != &rhs )
  70.       setACL( rhs.asString() );
  71.     return *this;
  72.   }
  73.  
  74.   bool operator==( const KACL& rhs ) const;
  75.  
  76.   bool operator!=( const KACL& rhs ) const {
  77.     return !operator==( rhs );
  78.   }
  79.  
  80.   /**
  81.    * Returns whether the KACL object represents a valid acl.
  82.    * @return whether the KACL object represents a valid acl.
  83.    */
  84.   bool isValid() const;
  85.  
  86.   /** The standard (non-extended) part of an ACL. These map directly to 
  87.    * standard unix file permissions. Setting them will never make a valid
  88.    * ACL invalid. */
  89.  
  90.   /** @return the owner's premissions entry */
  91.   unsigned short ownerPermissions() const;
  92.  
  93.   /** Set the owner's permissions entry.
  94.    * @return success or failure */
  95.   bool setOwnerPermissions( unsigned short );
  96.  
  97.   /** @return the owning group's premissions entry */
  98.   unsigned short owningGroupPermissions() const;
  99.  
  100.   /** Set the owning group's permissions entry.
  101.    * @return success or failure */
  102.   bool setOwningGroupPermissions( unsigned short );
  103.  
  104.   /** @return the premissions entry for others */
  105.   unsigned short othersPermissions() const;
  106.  
  107.   /** Set the permissions entry for others.
  108.    * @return success or failure */
  109.   bool setOthersPermissions( unsigned short );
  110.  
  111.   /** @return the basic (owner/group/others) part of the ACL as a mode_t */
  112.   mode_t basePermissions() const;
  113.  
  114.   /** The interface to the extended ACL. This is a mask, permissions for 
  115.    * n named users and permissions for m named groups. */
  116.  
  117.   /**
  118.    * Return whether the ACL contains extended entries or can be expressed
  119.    * using only basic file permissions.
  120.    * @return whether the ACL contains extended entries */
  121.   bool isExtended() const;
  122.  
  123.   /**
  124.    * Return the entry for the permissions mask if there is one and sets
  125.    * @p exists to true. If there is no such entry, @p exists is set to false.
  126.    * @return the permissions mask entry */
  127.   unsigned short maskPermissions( bool &exists ) const;
  128.  
  129.   /** Set the permissions mask for the ACL. Permissions set for individual 
  130.    * entries will be masked with this, such that their effective permissions
  131.    * are the result of the logical and of their entry and the mask. 
  132.    * @return success or failure */
  133.   bool setMaskPermissions( unsigned short );
  134.  
  135.   /** 
  136.    * Access to the permissions entry for a named user, if such an entry 
  137.    * exists. @p exists is set to true if a matching entry exists and
  138.    * to false otherwise.
  139.    * @return the permissions for a user entry with the name in @p name */
  140.   unsigned short namedUserPermissions( const QString& name, bool *exists ) const;
  141.  
  142.  
  143.   /** Set the permissions for a user with the name @p name. Will fail
  144.    * if the user doesn't exist, in which case the ACL will be unchanged.
  145.    * @return success or failure. */
  146.   bool setNamedUserPermissions( const QString& name, unsigned short );
  147.  
  148.   /** Returns the list of all group permission entries. Each entry consists
  149.    * of a name/permissions pair. This is a QPair, therefore access is provided 
  150.    * via the .first and .next members.
  151.    * @return the list of all group permission entries. */
  152.   ACLUserPermissionsList allUserPermissions() const;
  153.  
  154.   /** Replace the list of all user permissions with @p list. If one
  155.    * of the entries in the list does not exists, or setting of the ACL
  156.    * entry fails for any reason, the ACL will be left unchanged.
  157.    * @return success or failure */
  158.   bool setAllUserPermissions( const ACLUserPermissionsList &list );
  159.  
  160.   /**
  161.    * Access to the permissions entry for a named group, if such an entry 
  162.    * exists. @p exists is set to true if a matching entry exists and
  163.    * to false otherwise.
  164.    * @return the permissions for a group with the name in @p name */
  165.   unsigned short namedGroupPermissions( const QString& name, bool *exists ) const;
  166.  
  167.   /** Set the permissions for a group with the name @p name. Will fail
  168.    * if the group doesn't exist, in which case the ACL be unchanged.
  169.    * @return success or failure. */
  170.   bool setNamedGroupPermissions( const QString& name, unsigned short );
  171.  
  172.   /** Returns the list of all group permission entries. Each entry consists
  173.    * of a name/permissions pair. This is a QPair, therefor access is provided 
  174.    * via the .first and .next members.
  175.    * @return the list of all group permission entries. */
  176.  
  177.   ACLGroupPermissionsList allGroupPermissions() const;
  178.   /** Replace the list of all user permissions with @p list. If one
  179.    * of the entries in the list does not exists, or setting of the ACL
  180.    * entry fails for any reason, the ACL will be left unchanged.
  181.    * @return success or failure */
  182.   bool setAllGroupPermissions( const ACLGroupPermissionsList & );
  183.  
  184.   /** Sets the whole list from a string. If the string in @p aclStr represents 
  185.    * a valid ACL, it will be set, otherwise the ACL remains unchanged.
  186.    * @return whether setting the ACL was successful. */
  187.   bool setACL( const QString &aclStr );
  188.  
  189.   /** Return a string representation of the ACL.
  190.    * @return a string version of the ACL in the format compatible with libacl and
  191.    * POSIX 1003.1e. Implementations conforming to that standard should be able
  192.    * to take such strings as input. */
  193.   QString asString() const;
  194.  
  195. protected:
  196.   virtual void virtual_hook( int id, void* data );
  197. private:
  198.   class KACLPrivate;
  199.   KACLPrivate * d;
  200.   KIO_EXPORT friend QDataStream & operator<< ( QDataStream & s, const KACL & a );
  201.   KIO_EXPORT friend QDataStream & operator>> ( QDataStream & s, KACL & a );
  202. };
  203.  
  204. KIO_EXPORT QDataStream & operator<< ( QDataStream & s, const KACL & a );
  205. KIO_EXPORT QDataStream & operator>> ( QDataStream & s, KACL & a );
  206.  
  207. #endif
  208.